import request from '@/request'

export function getAllCategorys() {
  return request({
    url: '/categories',
    method: 'get',
  })
}

/*export function getAllCategorysDetail() {
  return request({
    url: '/categories/detail',
    method: 'get',
  })
}*/

export function getAllCategorysDetail() {
  return request({
    url: '/categories',
    method: 'get',
  })
}

export function getCategory(id) {
  return request({
    url: `/categories/${id}`,
    method: 'get',
  })
}

export function getCategoryDetail(id) {
  return request({
    url: `/categories/detail/${id}`,
    method: 'get',
  })
}

export function getCategoryForAdmin(token, page, formData) {
  return request({
    headers: {'Authorization': token},
    url: `/categories/admin/all`,
    method: 'post',
    data:{
      page: page.pageNumber,
      pageSize: page.pageSize,
      categoryName: formData.categoryName
    }
  })
}

export function changeCategory(token, formData){
  return request({
    headers: {'Authorization': token},
    url: `categories/admin/change`,
    method: 'post',
    data:{
      id: formData.id,
      categoryName: formData.categoryName,
      description: formData.description,
      avatar: formData.image
    }
  })
  
}


export function addCategory(token, formData){
  return request({
    headers: {'Authorization': token},
    url: 'categories/admin/add',
    method: 'post',
    data:{
      categoryName: formData.categoryName,
      description: formData.description,
      avatar: formData.image
    }
  })
  
}

export function deleteCategory(token, id){
  return request({
    headers: {'Authorization': token},
    url: `categories/admin/delete/${id}`,
    method: 'post'
  })
  
}

export function deleteCategoryList(token, arr){
  return request({
    headers: {'Authorization': token},
    url: `categories/admin/deleteList?arr=` + arr,
    method: 'get',
    
  })
  
}
